﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace Web.UI
{ 
    public class ManagePage:System.Web.UI.Page
    {
        BLL.WebLog log = new BLL.WebLog();
        BLL.NewsClass newsClass = new BLL.NewsClass();
        /// <summary>
        ///在load事件里面追加事件
        /// </summary>
        public ManagePage() {
            this.Load += new EventHandler(ManagePage_Load);
        }


        /// <summary>
        /// 定义要添加的ManagePage_Load事件
        /// </summary>
        /// <param name="sender">对象</param>
        /// <param name="e">事件</param>
        void ManagePage_Load(object sender,EventArgs e) {
            //if (Session["AdminName"] == null||Session["AdminType"]==null||Session["AdminPermission"]==null) {
            //    Response.Write("<script>parent.location.href='../Login.aspx'</script>");
            //    Response.End();
            //}
        }

        /// <summary>
        /// 信息显示类型树绑定
        /// </summary>
        /// <param name="parentId">最高父Id</param>
        /// <param name="firstItemText">下拉列表第一项显示的文字，如果为null，则不显示</param>
        /// <param name="ddl">下拉列表</param>
        public void ClassTreeBind(string firstItemText, DropDownList ddl) {
            DataTable dt = newsClass.GetNewsClass();
            ddl.Items.Clear();
            //判断第一项显示的文字是否为空，如果非空，则第一项文字加入
            if (firstItemText!= null && firstItemText.Trim() != " ")
            {
                ddl.Items.Add(new ListItem(firstItemText, " "));
            }
            if (dt != null)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    int id = (int)dr["NCId"];
                    string Title = dr["NCTitle"].ToString();
                    ddl.Items.Add(new ListItem(Title, id.ToString()));
                }
            }
           
        }
        /// <summary>
        /// 保存日志
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="str">用户状态</param>
        /// <param name="manageClass">用户类型</param>
        /// <returns>返回保存的行数</returns>
        public int SaveLog( string userName, string str, string manageClass) {
            int i;
            Model.WebLog weblog = new Model.WebLog();
            weblog.UserName = userName;
            weblog.Title = str;
            weblog.ManageClss = manageClass;
            if (HttpContext.Current.Request.UserHostAddress != null)
                weblog.IpAddress = HttpContext.Current.Request.UserHostAddress;
            i = log.AddSingleLog(weblog);
            return i;
        }
    }
}
